import SVGScaler from "../Preprocessors/SVGScaler";
import SVGSizer from "../Preprocessors/SVGSizer";
import { Point } from "../type";
import { MinMaxInfoSetting, TextSetting } from "../typeSC";


export default class TextCreator {
    textSetting: TextSetting;
    svgScaler: SVGScaler;
    svgSizer: SVGSizer;

    svg: any;
    el: any;
    position: Point;

    constructor(svg: any, textSetting: TextSetting, svgSizer: SVGSizer, svgScaler: SVGScaler) {
        this.svg = svg;

        this.textSetting = textSetting;
        this.svgScaler = svgScaler;
        this.svgSizer = svgSizer;

        this.position = svgSizer.getPosition(textSetting.id);

        this.el = svg.append('g').attr("data-type", textSetting.id).attr('transform', `translate(${this.position?.x ?? 0}, ${this.position?.y ?? 0})`);
    }

    draw() {
        const height = this.textSetting['height'];
        
        const font = this.textSetting['font_family'] ?? 'times new roman';
        const weight = this.textSetting['font_weight'] ?? 'bold';
        const size = this.textSetting['font_size'] ?? 20;
        
        this.el.append('g').attr('transform', `translate(0, ${height / 2 + size / 3})`).attr("data-type", "min-max-label")
                    .append('text')
                    .text(this.textSetting.text)
                    .attr('class', 'draggable')
                    .attr('font-family', font)
                    .attr('font-size', size)
                    .attr('font-weight', weight)
                    .style("text-anchor", "start")
                    .attr("fill", 'black');
        
    }
}